<template>
  <div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
      </a-dropdown>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table
        ref="table"
        size="middle"
        :scroll="{x:true}"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <mdm-customer-contacts-modal ref="modalForm" @ok="modalFormOk" :init-add-model="initAddModel"></mdm-customer-contacts-modal>
  </div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import MdmCustomerContactsModal from './modules/MdmCustomerContactsModal'
  import JEllipsis from '@/components/jeecg/JEllipsis'
  import {getAction} from "@/api/manage";

  export default {
    name: 'MdmCustomerContactsTable',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      MdmCustomerContactsModal,
      JEllipsis
    },
    data () {
      return {
        description: '联系人管理页面',
        // 表头
        columns: [
          {
            title:'姓名',
            align:"center",
            dataIndex: 'name',
            width:100,
            scopedSlots: { customRender: 'name' }
          },
          {
            title:'客户名称',
            align:"center",
            width:120,
            dataIndex: 'customerId_dictText',
            scopedSlots: { customRender: 'customerId_dictText' }
          },
          {
            title:'手机',
            align:"center",
            dataIndex: 'mobile',
            width:100
          },
          {
            title:'部门',
            align:"center",
            dataIndex: 'dept',
            width:100
          },
          {
            title:'职务',
            align:"center",
            dataIndex: 'post',
            width:100
          },
          {
            title:'属性',
            align:"center",
            dataIndex: 'prop_dictText',
            width:100
          },
          {
            title:'地址',
            align:"center",
            dataIndex: 'homeAddress',
            width:160
          },
          {
            title:'民族',
            align:"center",
            dataIndex: 'nation_dictText',
            width: 60
          },
          {
            title:'性别',
            align:"center",
            dataIndex: 'sex_dictText',
            width: 60
          },
          {
            title:'年龄段',
            align:"center",
            dataIndex: 'ageGroup_dictText',
            width: 100
          },
          {
            title:'电话',
            align:"center",
            dataIndex: 'telephone',
            width: 100
          },
          {
            title:'邮箱',
            align:"center",
            dataIndex: 'email',
            width: 100
          },
          {
            title:'备注',
            align:"center",
            dataIndex: 'remark',
            width: 160
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/mdm/customerContacts/list",
          delete: "/mdm/customerContacts/delete",
          deleteBatch: "/mdm/customerContacts/deleteBatch",
        },
        dictOptions:{},
        superFieldList:[],
      }
    },
    props:{
      initQueryParam:{},
      initAddModel:{}
    },
    created() {
      this.getSuperFieldList();
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'姓名',dictCode:''})
        fieldList.push({type:'popup',value:'customerId',text:'客户ID', popup:{code:'mdm_customer_pop',field:'id',orgFields:'id',destFields:'customer_id'}})
        fieldList.push({type:'string',value:'sex',text:'性别',dictCode:'sex'})
        fieldList.push({type:'string',value:'mobile',text:'手机号',dictCode:''})
        fieldList.push({type:'string',value:'telephone',text:'电话',dictCode:''})
        fieldList.push({type:'string',value:'ageGroup',text:'年龄段',dictCode:'crm_age_group'})
        fieldList.push({type:'string',value:'wechat',text:'微信',dictCode:''})
        fieldList.push({type:'string',value:'qq',text:'QQ',dictCode:''})
        fieldList.push({type:'string',value:'email',text:'邮箱',dictCode:''})
        fieldList.push({type:'string',value:'officeAddress',text:'办公地址',dictCode:''})
        fieldList.push({type:'sel_search',value:'nation',text:'民族',dictTable:'sys_dict_item', dictText:'item_text', dictCode:'item_value'})
        fieldList.push({type:'date',value:'birthday',text:'生日'})
        fieldList.push({type:'string',value:'homeAddress',text:'家庭地址',dictCode:''})
        fieldList.push({type:'string',value:'hobby',text:'兴趣爱好',dictCode:''})
        fieldList.push({type:'string',value:'trait',text:'性格特征',dictCode:''})
        fieldList.push({type:'string',value:'taboo',text:'忌讳事项',dictCode:''})
        fieldList.push({type:'string',value:'remark',text:'备注',dictCode:''})
        this.superFieldList = fieldList
      },
      loadData(arg) {
        if(!this.url.list){
          this.$message.error("请设置url.list属性!")
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination.current = 1;
        }
        Object.assign(this.queryParam, this.initQueryParam);
        var params = this.getQueryParams();//查询条件
        this.loading = true;
        getAction(this.url.list, params).then((res) => {
          if (res.success) {
            //update-begin---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
            this.dataSource = res.result.records||res.result;
            if(res.result.total)
            {
              this.ipagination.total = res.result.total;
            }else{
              this.ipagination.total = 0;
            }
            //update-end---author:zhangyafei    Date:20201118  for：适配不分页的数据列表------------
          }else{
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading = false
        })
      },
    }
  }
</script>
<style scoped>
  .ant-card-body .table-operator {
    margin-bottom: 0px;
  }
</style>